﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;
using System.Data;
using System.Web.Script.Serialization;

namespace FubiManger.Settlement
{
    partial class SettlementForm : Smobiler.Core.Controls.MobileForm
    {
        public SettlementForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        public string merchantid { get; set; }
        int timer = 3;
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer--;
            if (timer == 0)
            {
                timer = 3;
                ms_merchant merchant = merchantDal.Querybyid(merchantid);
                ms_order_mark mark = order_markDal.Querybymerchantid(merchantid);
                if (!string.IsNullOrEmpty(mark.price))
                {
                    lblname.Text = merchant.merchant_name;//商家名称
                    this.Form.BackgroundImage = "";
                    panall.Visible = true;
                    lblprice.Text = "金额：￥" + mark.price;
                    JavaScriptSerializer js = new JavaScriptSerializer();   //实例化一个能够序列化数据的类
                    List<Gdpro> prolist = js.Deserialize<List<Gdpro>>(mark.goods);
                    DataTable table = new DataTable();
                    table.Columns.Add("gdname");
                    table.Columns.Add("count");
                    table.Columns.Add("price");
                    if (lvgoods.Rows.Count > 0)
                        lvgoods.Rows.Clear();
                    for (int i = 0; i < prolist.Count; i++)
                    {
                        table.Rows.Add(prolist[i].proname,"x"+ prolist[i].count, "￥"+prolist[i].price);
                    }
                    lvgoods.DataSource = table;
                    lvgoods.DataBind();
                }
                else
                {
                    lvgoods.Rows.Clear();
                    this.Form.BackgroundImage = "20230726163418";
                    panall.Visible = false;
                }
            }
        }

        private void SettlementForm_Load(object sender, EventArgs e)
        {
            timer1.Start();
        }

        private void button1_Press(object sender, EventArgs e)
        {
            if (button1.Text == "显示")
            {
                button1.Text = "不显示";
                this.Form.BackgroundImage = "20230726163418";
                panall.Visible = false;
            }
            else
            {
                button1.Text = "显示";
                this.Form.BackgroundImage = "";
                panall.Visible = true;
            }
        }
    }
}